using NUnit.Framework;
using Tycho.Parser.Peg;
using Tycho.Parser.Syntax;

namespace Tycho.Parser.Tests.Syntax {
    [TestFixture]
    public class SequenceSyntaxSpecification {
        [Test]
        public void AccumulateCapturesShouldAddAllCaptures() {
            var sequence = new SequenceSyntax (new CaptureSyntax ("a", null), new CaptureSyntax ("b", null));

            CaptureAccumulator accumulator = new CaptureAccumulator ();
            sequence.AccumulateCaptures (accumulator);

            Assert.AreEqual (false, accumulator.Captures ["a"]);
            Assert.AreEqual (false, accumulator.Captures ["b"]);
        }

        [Test]
        public void CompileShouldLeaveIsFirstForFirstItemThenSetTrueForRemaining() {
            FakeIsFirstSyntax left = new FakeIsFirstSyntax ();
            FakeIsFirstSyntax right = new FakeIsFirstSyntax ();
            var sequence = new SequenceSyntax (left, right);

            sequence.Compile (new ProductionLookup (null, null, null));

            Assert.AreEqual (true, left.WasFirst);
            Assert.AreEqual (true, left.WasFirst);
        }
    }

    class FakeIsFirstSyntax : Parser.Syntax.Syntax {
        public bool WasFirst;

        public override Production Compile (ProductionLookup productionLookup) {
            WasFirst = productionLookup.IsFirst;
            return null;
        }

        public override void AccumulateCaptures (ICaptureAccumulator accumulator) {
            throw new System.NotImplementedException ();
        }
    }
}